// TypeScript file
class locationwnd extends eui.Component{

    public ON_CLOSE:string = "close";
    private contentBg:egret.Sprite;
    private wndGroup:windowGroup;
    private btnClose:eui.Image;
    private btnOk:eui.Image;
    private tx_clew:eui.Label;
    private kuang:eui.Image;

	public constructor() {//(用户1数据,用户2数据);
		super();        
        this.addEventListener(eui.UIEvent.COMPLETE,this.onComplete,this);
		this.skinName = "src/Game/gameRoom/location/locationSkin.exml";				
	}
	private onComplete():void{
        this.tx_clew.text = "正在定位中...";
        this.contentBg = new egret.Sprite();
        this.wndGroup = new windowGroup(736,372,this.contentBg);
        this.addChild(this.wndGroup);
        this.wndGroup.x = 218;
        this.wndGroup.y = 166;
        this.once(egret.Event.REMOVED_FROM_STAGE,this.onRemove,this);
        this.btnOk.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onClick,this);
        this.btnClose.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onClick,this);
	}
    private onRemove(e:egret.Event){
        this.btnOk.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onClick,this);
        this.btnClose.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onClick,this);
    }
    private onClick(e:egret.TouchEvent){
        this.dispatchEventWith(this.ON_CLOSE);
    }
    public setContent(listData:any){    
        if(!listData||listData.length<1){
            this.tx_clew.text = "没有其他玩家的位置";
            this.tx_clew.visible = true;
            return;
        }
        if(this.contentBg.numChildren){
            for(var i=this.contentBg.numChildren;i>0;i--){
                this.contentBg.removeChildAt(i-1);
            }
        }
        if(listData.length == 2){
            var bg1:locationBg1 = new locationBg1(listData);
            bg1.x = 90;
            bg1.y = 120;
            this.contentBg.addChild(bg1);
        }else if(listData.length == 3){
            var bg2:locationBg2 = new locationBg2(listData);
            bg2.x = 90;
            this.contentBg.addChild(bg2);
        }else if(listData.length == 5){
            var bg3:locationBg3 = new locationBg3(listData);
            bg3.x = 120;
            this.contentBg.addChild(bg3);
        }else{            
            for(var i=0;i<listData.length;i++){
                var obj:locationObj = new locationObj(listData[i]);//listData[i]
                obj.y = (obj.height+5)*i;
                obj.x = 50;
                this.contentBg.addChild(obj);
            } 
        }        
        this.tx_clew.visible = false; 
        this.wndGroup.updateData();        
    }    
}